package com.flashcash.kotlin.activity

import android.content.Context
import android.content.Intent
import android.support.design.widget.TabLayout
import android.support.v4.view.ViewPager
import android.widget.ImageButton
import android.widget.TextView
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.flashcash.solu.R
import com.flashcash.solu.app.base.BaseActivity
import com.flashcash.solu.app.base.presenter.BaseActivityPresenter
import com.flashcash.solu.app.base.presenter.BaseActivityPresenterImpl
import com.flashcash.solu.view.MsgBoxActivity
import com.flashcash.kotlin.adapter.CouponAdapter
import com.flashcash.kotlin.fragment.CouponFragment
import com.flashcash.kotlin.router.RouteExtraConst
import org.jetbrains.anko.find
import org.jetbrains.anko.sdk25.coroutines.onClick

/**
 * @作者:XLEO
 * @创建日期: 2017/8/11 17:30
 * @描述: 用户券列表页
 *
 * @更新者:${Author}$
 * @更新时间:${Date}$
 * @更新描述:${TODO}
 * @下一步：
 */
@Route(path = "/user/coupons", extras = RouteExtraConst.IsNeedLogin)
class MyCouponActivity : BaseActivity<MyCouponPresenter>(), MyCouponView {
    companion object {
        fun actionStart(context: Context?) {
            ARouter.getInstance()
                    .build("/user/coupons")
                    .navigation(context)
        }
    }

    lateinit var vp: ViewPager
    override fun getLayoutResId(): Int {
        return R.layout.activity_my_coupon
    }

    override fun init() {
        find<ImageButton>(R.id.id_imagebutton_back).onClick { finish() }
        find<TextView>(R.id.id_textview_title).text = getString(R.string.title_coupon)
        find<ImageButton>(R.id.id_imagebutton_info_list).onClick { startActivity(Intent(applicationContext, MsgBoxActivity::class.java)) }
        vp = find(R.id.vp_coupon)
        val fragments = arrayOf(CouponFragment().setType(CouponFragmentType.Available),
                CouponFragment().setType(CouponFragmentType.Used),
                CouponFragment().setType(CouponFragmentType.Expired))
        val titles = arrayOf(getString(R.string.page_title_coupon1), getString(R.string.page_title_coupon2), getString(R.string.page_title_coupon3))
        find<TabLayout>(R.id.tl_coupon).setupWithViewPager(vp)
        vp.adapter = CouponAdapter(fragments, titles, supportFragmentManager)
    }

    override fun initPresenterImpl(): MyCouponPresenter {
        return MyCouponPresenterImpl()
    }

}

class MyCouponPresenterImpl : BaseActivityPresenterImpl(), MyCouponPresenter {

}

interface MyCouponView {

}

interface MyCouponPresenter : BaseActivityPresenter {
}

enum class CouponFragmentType(type: Int) {
    Available(type = 1),
    Used(type = 2),
    Expired(type = 3)
}